-
Notifications
You must be signed in to change notification settings - Fork 3
Feature: Convert menus to JSON #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Check out the recent updates to your Headless Platform preview environment:
Learn more about preview environments in our documentation. |
kellenmace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colinmurphy So, you executed on the new JSON file approach for this feature beautifully, but now seeing it implemented, I'm wondering if maybe this approach is unnecessarily complex. 😅
What if we just hardcode the menu links directly in the primary-nav and footer files?
The menus are not used anywhere else in the app, so there's no real reason why they need to live in a separate menus.js file. And with the current approach, we have to jump through a bunch of hoops:
- Add unique
ids for the menu items so that when we map over them we can pass those in as thekeyprop to appease React - Add a
sectionproperty for every object to keep track of which column it's supposed to be in. - Do filtering in the footer file to sort the menu items in three lists
- Map over the menu items and render the nav links
If we hardcode the nav links directly in the primary-nav and footer files, we could wipe out all of those steps and simplify this code significantly. We'd have to repeat the className class lists for each column and nav link, but I don't have a problem with that.
What do you think of this simpler hardcoding approach, @colinmurphy & @Fran-A-Dev?
src/constants/menus.js
Outdated
| target: "_blank", | ||
| }, | ||
| { | ||
| id: "dicord", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here– missing an "s". Not that it matters too much, since this is just a unique ID that end users never see :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Kellen :)
src/constants/menus.js
Outdated
| export const PRIMARY_LOCATION = "PRIMARY"; | ||
| export const FOOTER_LOCATION = "FOOTER_1"; | ||
|
|
||
| export const HeaderMenu = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name this using camelCase instead of PascalCase here. By convention, PascalCase is typically used for classes and React components and camelCase is used for other variables like this array. When I first glanced at this PR and saw HeaderMenu, my first thought was that it was a React component that was being imported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Kellen, That is really useful feedback. I wasn't aware of the different conventions for React. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya same with the HeaderMenu in my mind being a React component.
src/components/footer.jsx
Outdated
|
|
||
| return columns.map((column, index) => { | ||
| if (!column || column.length === 0) { | ||
| return; // Skip rendering if no menu items are found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per this section of the React docs (https://react.dev/learn/conditional-rendering#conditionally-returning-nothing-with-null), the recommended way to render nothing is to return null. So this line should do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Kellen, That is good to know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Kellen for the really good feedback. I can definitely see where your coming from and I agree with your approach too. There is definitely too much overhead for some static links which are not going to be re-used elsewhere. We could also probably set a variable for the class names to try and reduce repetition too.
Agreed @kellenmace , this is how I would do it myself as well. Keeping this as simple as possible. I tend to hardcode things whenever possible and if it is the best approach to keep it simple. |
|
Check out the recent updates to your Headless Platform preview environment:
Learn more about preview environments in our documentation. |
|
The PR has now been updated as per code review (thanks for the feedback) and the links are now hardcoded. |
|
I disagree completely with Kellen and Fran but 🤷♂️. The first system was over engineered but directly replaced the JS API without engineering the HTML/CSS. You didn't need the Kellen can make the call but I would have refined the previous idea instead of re-engineering something that has to be undone when we revert to WP menus. |
src/components/footer.jsx
Outdated
| className={linkClass} | ||
| href="https://www.npmjs.com/package/@faustwp/cli" | ||
| noDefaultStyles | ||
| target="_blank" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is handled by the component.
src/components/footer.jsx
Outdated
| </li> | ||
| </ul> | ||
| </div> | ||
| <div className={columnClass} key="community"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keys are unneeded if we're not mapping over an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colinmurphy @kellenmace @moonmeister I am for whatever ya'll decide is best! Stoked
|
Thanks Alex for the feedback. I won't do anything further here until Kellen reviews. Happy to do either approach. In hindsight the filter approach was a bit too complex and going with 3 objects instead would of been the better approach. |
|
|
Check out the recent updates to your Headless Platform preview environment:
Learn more about preview environments in our documentation. |
|
@kellenmace @Fran-A-Dev @moonmeister This is now ready to be reviewed again. As per call I removed the key and target elements. I also double checked that privacy policy link does not open a new window too. |
|
Check out the recent updates to your Headless Platform preview environment:
Learn more about preview environments in our documentation. |
|
Check out the recent updates to your Headless Platform preview environment:
Learn more about preview environments in our documentation. |
kellenmace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This last iteration looks great to me. Thanks @colinmurphy! 👍🏼
Overview:
I converted the header and footer menus into static menus using a JSON array.
The purpose of this task was firstly to remove the loading text on the initial page load and also to add SSR.
One tradeoff was around having 3 menus or just one menu for the footer which we could filter. I considered 3 menus but I found that the code was cleaner with one menu and I was able to filter each section.
QA
Screenshots below